package cxt.com.recyclerview.demo1;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;

import java.util.ArrayList;

import cxt.com.recyclerview.R;

/**
 * Demo1：RecyclerView的基本使用。
 * - 为RecyclerView添加OnItemClickListener接口。
 * - ItemDecoration的范例：DividerItemDecoration。
 * - 为RecyclerView实现Headerview和Footerview。
 */

public class MainActivity1 extends AppCompatActivity {
    public RecyclerView mRecyclerView;
    public NormalAdapter mNormalAdapter;
    public ArrayList<DataModel> mDataModel = null;
    public DividerItemDecoration mDividerItemDecoration;
    public NormalAdapterWrapper mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main1);
        initView();
    }

    private void initView() {
        mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mDividerItemDecoration = new DividerItemDecoration(this, LinearLayoutManager.VERTICAL);
        mRecyclerView.addItemDecoration(mDividerItemDecoration);

        mDataModel = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            DataModel dataModel = new DataModel();
            dataModel.setTitle("文本" + i);
            dataModel.setNumber(i);
            mDataModel.add(dataModel);
        }
        mNormalAdapter = new NormalAdapter(this, mDataModel);
        mAdapter = new NormalAdapterWrapper(mNormalAdapter);
        View headerView = LayoutInflater.from(this).inflate(R.layout.item_header, mRecyclerView, false);
        View footerView = LayoutInflater.from(this).inflate(R.layout.item_footer, mRecyclerView, false);
        mAdapter.addFooterView(footerView);
        mAdapter.addHeaderView(headerView);
        mRecyclerView.setAdapter(mAdapter);

    }
}
